//
//  VideoView.m
//  thunder_framework
//
//  Created by dragon on 11/10/10.
//  Copyright 2010 Thunder Networking Inc. All rights reserved.
//

#include "ekk_interface.h"
#import "EkkVideoView.h"
#import "ES2Renderer.h"

#ifdef	LOGID
#undef	LOGID
#endif

#define LOGID	LOGID_UI //LOGID_IPHONE_THUNDER_VIDEO_VIEW

#if 0
#import <pthread.h>
#define LOG_FUNC_CALL()  NSLog(@"[TVOUT %d]CALL %s :%d",self,__FUNCTION__,__LINE__);
#define LOGDB NSLog
#else
#define LOG_FUNC_CALL(...) 
#define LOGDB(...) 
#endif


// …˘√˜£∫
//extern void hdmi_player_show_control_forever(BOOL flag);

// µ˜”√£∫
// ipadkk_hdmi_player_show_control_forever(TRUE);
@implementation EkkVideoView

@synthesize subtitle_lable;
@synthesize is_tvout_running;

+ (Class)layerClass
{
	return [CAEAGLLayer class];
}

- (id) initWithCoder:(NSCoder*)coder
{
	LOG_FUNC_CALL();
    
	if (self = [super initWithCoder:coder]) {
		render = NULL;
		buffer = NULL;
		video_logo_buffer = NULL;
		self.opaque = NO;
		self.clearsContextBeforeDrawing = YES;
		
		CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;
        
		eaglLayer.opaque = TRUE;
		eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
										[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        //render = [[ES2Renderer alloc] init];
        //[self set_video_rect:&frame src_rect_name:&frame];
	}
    zoom = 1.0;
	tv_window = nil;
	org_SuperView = nil;
	//init TVout.  enable it by default
	is_tvout_enable = 1;
	is_tvout_running = 0;
    [self update_TVout];
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
    [center addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
    //   [center addObserver:self selector:@selector(screenModeDidChange:) name:UIScreenModeDidChangeNotification object:nil];
    is_render_paused = NO;
    is_rendering = NO;
    is_clearing_black = NO;
    black_hidden = NO;
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
	LOG_FUNC_CALL();

	if (self = [super initWithFrame:frame]) {
		render = NULL;
		buffer = NULL;
		video_logo_buffer = NULL;
		//self.opaque = NO;
		//self.clearsContextBeforeDrawing = YES;
		
		CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer;

		eaglLayer.opaque = TRUE;
		eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
										[NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        //render = [[ES2Renderer alloc] init];
        //[self set_video_rect:&frame src_rect_name:&frame];
	}
    zoom = 1.0;
	tv_window = nil;
	org_SuperView = nil;
	//init TVout.  enable it by default
	is_tvout_enable = 1;
	is_tvout_running = 0;
    [self update_TVout];
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(screenDidConnect:) name:UIScreenDidConnectNotification object:nil];
    [center addObserver:self selector:@selector(screenDidDisconnect:) name:UIScreenDidDisconnectNotification object:nil];
 //   [center addObserver:self selector:@selector(screenModeDidChange:) name:UIScreenModeDidChangeNotification object:nil];
    is_render_paused = NO;
    is_rendering = NO;
    is_clearing_black = NO;
    black_hidden = NO;
    return self;
}

- (long)set_video_rect:(CGRect*) rect src_rect_name:(CGRect*)src_rect
{
	LOG_FUNC_CALL();
	long ret = 1;
	if (rect && src_rect)
	{
        video_rect = *rect;
		video_src_rect = *src_rect;
	}
	if (buffer)
	{
		ekk_free(buffer);
		buffer = NULL;
	}
	if (!render)
	{
		render = [[ES2Renderer alloc] init];

	}
	if (render)
	{
		CGRect t_rect ;
		t_rect = *rect;
		if(is_tvout_running && tv_window)
		{
			t_rect.origin.x = 0;
			t_rect.origin.y = 0;
			t_rect.size.width = tv_window.screen.currentMode.size.width;
			t_rect.size.height = tv_window.screen.currentMode.size.height;
		}
		ret = [((ES2Renderer*)render) set_video_rect:(&t_rect) src_rect_name:src_rect];
		if (EKK_ERROR_NONE == ret)
		{
			
            [((ES2Renderer*)render) set_video_logo:&video_logo_rect logo_buffer_name:video_logo_buffer logo_size_name:&video_logo_size];
            [((ES2Renderer*)render) set_video_subtitle:&video_subtitle_rect subtitle_buffer_name:video_subtitle_buffer subtitle_size_name:&video_subtitle_size];
            return ret;
			[((ES2Renderer*)render) release];
		}
	}
	return ret;
}

- (long) set_video_logo:(CGRect*)logo_rect logo_buffer_name:(unsigned char *)logo_buffer logo_size_name:(CGSize*)logo_size
{
	LOG_FUNC_CALL();

	long ret = 1;
	if (render)
	{
		ret = [((ES2Renderer*)render) set_video_logo:logo_rect logo_buffer_name:logo_buffer logo_size_name:logo_size];
	}
	else
	{
		video_logo_rect = *logo_rect;
		video_logo_buffer = logo_buffer;
		video_logo_size.width = logo_size->width;
		video_logo_size.height = logo_size->height;
		ret = 0;
	}
	return ret;
}

- (long) set_video_subtitle:(CGRect*)subtitle_rect subtitle_buffer_name:(unsigned char *)subtitle_buffer subtitle_size_name:(CGSize*)subtitle_size
{
	LOG_FUNC_CALL();
	
	long ret = 1;
	if (render)
	{
		ret = [((ES2Renderer*)render) set_video_subtitle:subtitle_rect subtitle_buffer_name:subtitle_buffer subtitle_size_name:subtitle_size];
	}
	else
	{
		video_subtitle_rect = *subtitle_rect;
		video_subtitle_buffer = subtitle_buffer;
		video_subtitle_size.width = subtitle_size->width;
		video_subtitle_size.height = subtitle_size->height;
		ret = 0;
	}
	return ret;
}

- (long) has_video_rect
{
	LOG_FUNC_CALL();
	
	if (render)
		return TRUE;
	else
		return FALSE;
}

- (unsigned char *) get_video_buffer
{
	LOG_FUNC_CALL();
	return buffer;
}

- (long) render_video:(unsigned char *)video_buffer buffer_len:(long)length y:(int)linesize_y u:(int)linesize_u v:(int)linesize_v;
{
	//LOG_FUNC_CALL();
    is_rendering = YES;
	
    if (render && !is_render_paused)
    {
        if (is_clearing_black)
        {
            //[((ES2Renderer*)render) clear_to_black];
        }
        else if (video_buffer && length >= [self get_video_buffer_mempitch])
        {
            [((ES2Renderer*)render) render_buffer:video_buffer y:linesize_y u:linesize_u v:linesize_v];
        }
        else
        {
            [((ES2Renderer*)render) refresh_video];
        }
    }
    //[self performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES];
    is_rendering = NO;
    
	return 0;
}

- (long) render_subtitle_pic:(unsigned char*)subtitle_pic_buffer
{
	LOG_FUNC_CALL();
	
	if (subtitle_pic_buffer) {
		[((ES2Renderer*)render) render_subtitle_pic:subtitle_pic_buffer];
	}
	return 0;
}

- (long) get_video_buffer_mempitch
{
//	LOG_FUNC_CALL();
	return video_src_rect.size.width * 4;
}

- (long) set_video_size_mode:(long)size_mode
{
	LOG_FUNC_CALL();
	
	if (render)
	{
		return [((ES2Renderer*)render) set_size_mode:size_mode];
	}
	return 1;
}

- (long) get_video_size_mode
{
	LOG_FUNC_CALL();
	
	if (render)
	{
		return [((ES2Renderer*)render) get_size_mode];
	}
	return -1;
}

- (long) refresh_video
{
	LOG_FUNC_CALL();
    long ret_val = 0;
	is_rendering = YES;
    
	if (render && !is_render_paused)
	{
        if (is_clearing_black)
        {
            //[((ES2Renderer*)render) clear_to_black];
        }
        else
        {
            ret_val = [((ES2Renderer*)render) refresh_video];
        }
	}
    
    is_rendering = NO;
	return ret_val;
}


- (void) layoutSubviews
{
	LOG_FUNC_CALL();
	
    [((ES2Renderer*)render) resizeFromLayer:(CAEAGLLayer*)self.layer];
    [self render_video:NULL buffer_len:0 y:0 u:0 v:0];
}


- (void) screenDidConnect:(NSNotification *)aNotification{
	LOG_FUNC_CALL();
	
	[self update_TVout];
}
 
- (void) screenDidDisconnect:(NSNotification *)aNotification{
	LOG_FUNC_CALL();
	
	[self update_TVout];
	//hdmi_player_show_control_forever(FALSE);
}
 
//- (void) screenModeDidChange:(NSNotification *)aNotification{
//    UIScreen *someScreen = [aNotification object];
//    NSLog(@"[TVOUT][Notify]The screen mode for a screen did change: %@", [someScreen currentMode]);
//	need_reset_tvout = YES;
//	[self setup_TVout:YES];
//}
- (long)detect_TVout
{
	LOG_FUNC_CALL();
	
    if (![UIScreen respondsToSelector:@selector(screens)])
    {
        return 0;
    }
    if ([[UIScreen screens] count] < 2)
    {
        return 0;
    }	
    return 1;
}

//enable or disable TVout feature, TVout only running both enable and TV is connected.
- (long) setup_TVout:(long)enable
{
	LOG_FUNC_CALL();
	
	is_tvout_enable = enable;
	if(is_tvout_enable || is_tvout_running)
		[self update_TVout];
	return  0;
}

//update TVout state
- (long) update_TVout
{	
	LOG_FUNC_CALL();
	
	[self destory_TVout];
	is_tvout_running = 0;

	if(is_tvout_enable)
	{
	
		LOGDB(@"[TVOUT %d]  update_TVout screen_count=%d", self,[[UIScreen screens] count]);
		if([[UIScreen screens] count] > 1)
		{
		
			//1. get external window&screen 
			UIScreen *tv_screen = [[UIScreen screens] lastObject];	
			UIScreenMode * maxScreenMode = [[tv_screen availableModes] lastObject];
			CGRect tv_Rect = CGRectMake(0,0, [maxScreenMode size].width, [maxScreenMode size].height);		
			LOGDB(@"[TVOUT %d] update_TVout tv_screen: %@",self, [NSString stringWithFormat:@"%@", tv_screen]);
            
			[tv_screen setCurrentMode:maxScreenMode];
			tv_window = [[UIWindow alloc] initWithFrame: tv_Rect];
			tv_window.screen = tv_screen;
			LOGDB(@"[TVOUT %d] [tv_window.screen bounds].size: %f %f",self, [tv_window.screen bounds].size.width, [tv_window.screen bounds].size.height);	
			LOGDB(@"[TVOUT %d] tv_screen.currentMode.size: %f %f",self, tv_screen.currentMode.size.width, tv_screen.currentMode.size.height);
			[tv_window makeKeyAndVisible];
			tv_window.bounds = [tv_window.screen bounds];
			tv_window.frame = [tv_window.screen bounds];	
			//tv_window.userInteractionEnabled = NO;
			tv_window.hidden = NO;	

			//2. set TVout
			if(nil == org_SuperView)
			{
				org_SuperView = [self superview];
		        LOGDB(@"[TVOUT %d]update_TVout org_SuperView=%d",self,org_SuperView);				
			}
			if(render)
			{
				CGRect rect;					
				rect.origin.x = 0;
				rect.origin.y = 0;
				rect.size.width = tv_window.bounds.size.width;
				rect.size.height = tv_window.bounds.size.height;
				[((ES2Renderer*)render) update_video_rect:&rect src_rect_name:&video_src_rect];
				LOGDB(@"[TVOUT %d]update_TVout render_set_video_rect=(%d,%d,%d,%d)",\
					self,rect.left,rect.top,rect.right,rect.bottom);
			}
			[self setBounds:[tv_window bounds]];
			[self setFrame:[tv_window bounds]];            
            
	        is_tvout_running = 1;
            [self calc_zoom_scale];
            if(subtitle_lable != nil)
            {
                [self set_video_subtitle_attribute:NULL fontEffect:subt_font_effect fontSize:subt_font_size fontColor:subt_font_color ];
            }
            
			[tv_window addSubview: self];

			//hdmi_player_show_control_forever(TRUE);
			LOGDB(@"[TVOUT %d]update_TVout View is out to TV %f,%f",self,[self bounds].size.width, [self bounds].size.height);
            
	        return 1;
		}
	}
    
    [self calc_zoom_scale];
    if(subtitle_lable != nil)
    {
        [self set_video_subtitle_attribute:NULL fontEffect:subt_font_effect fontSize:subt_font_size fontColor:subt_font_color ];
    }
	return 0;
}

- (void)destory_TVout
{
	LOG_FUNC_CALL();
	
	if(tv_window) 
	{
		LOGDB(@"[TVOUT %d]  cancel_TVout subview_count=%d",self,[[tv_window subviews] count]);
		//ªπ‘≠œ‘ æµΩipad
		if([[tv_window subviews] count]>0)
		{
			UIView *vw = [[tv_window subviews] lastObject];
			vw.frame = org_SuperView.bounds;
			if(render) 
			{
				[((ES2Renderer*)render) update_video_rect:&video_rect src_rect_name:&video_src_rect];
				LOGDB(@"[TVOUT %d]destory_TVout render_set_video_rect=(%d,%d,%d,%d)",\
					self,video_rect.left,video_rect.top,video_rect.right,video_rect.bottom);
				
			}
			[org_SuperView addSubview:vw];
			[org_SuperView sendSubviewToBack:vw];//±‹√‚’⁄◊°øÿ÷∆Ãı            
            //[org_SuperView bringSubviewToFront:vw];

		}
		[tv_window release];
		tv_window = nil;
	}
}


-(long) create_video_subtitle:(enum SUBTITLE_TYPE)type
{
    
    //printf("create_video_subtitle:type=%d  %d %u %x\n",type, subt_font_effect,subt_font_size,subt_font_color);
    
    if(type == SUBTITLE_TYPE_TEXT && subtitle_lable == nil)
    {
        subtitle_lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
        [subtitle_lable setBackgroundColor:[UIColor clearColor]];
        [subtitle_lable setOpaque:NO]; 
        [subtitle_lable setTextAlignment:UITextAlignmentCenter];
        
        [self addSubview:subtitle_lable];
        [self bringSubviewToFront:subtitle_lable];
        return 0;
        
    }
    else if(type == SUBTITLE_TYPE_IMAGE && subtitle_imageview == nil)
    {
        subtitle_imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
        [subtitle_imageview setBackgroundColor:[UIColor clearColor]];
        [subtitle_imageview setOpaque:NO]; 
        [subtitle_imageview setContentMode:UIViewContentModeScaleToFill];
        [self addSubview:subtitle_imageview];
        [self bringSubviewToFront:subtitle_imageview];
        return 0;
        
    }
    return -1;
}

-(long) destory_video_subtitle
{
    if(subtitle_lable != nil)
    {
        [subtitle_lable release];
        subtitle_lable = nil;
    }
    if(subtitle_imageview != nil)
    {
        [subtitle_imageview release];
        subtitle_imageview = nil;
    }
    
    return 0;
}

#define IS_FLOAT_EQUAL(x,y) ( (x-y < 0.000001) && (x-y > -0.000001) )
- (void)calc_zoom_scale
{   
	if(is_tvout_running && tv_window)
	{
		//get main screen size
	   CGSize main_frame_size = [[UIScreen mainScreen] bounds].size;
	   
	   CGFloat w = (main_frame_size.width > main_frame_size.height) ? main_frame_size.width : main_frame_size.height;
	   if( (IS_FLOAT_EQUAL(w,480)) || (IS_FLOAT_EQUAL(w,960)) ) //if device is iPhone!!!
	   {
		   main_frame_size.width = 480;
		   main_frame_size.height = 320;			
	   }
	   //get tv screen size 
	   CGRect tv_frame = tv_window.frame;
	   
	   CGFloat wzoom = tv_frame.size.width / main_frame_size.width;
	   CGFloat hzoom = tv_frame.size.height / main_frame_size.height;
	   
	   zoom = (wzoom > hzoom) ? hzoom : wzoom;
	}
    else
    {
        zoom = 1.0;
    }
    
    //printf("calc_zoom_scale:zoom=%f %d %u %x\n",zoom, subt_font_effect,subt_font_size,subt_font_color);
}
-(void)conv_frame_size:(CGRect*)frame
{
    if(is_tvout_running && tv_window)
    {
        frame->origin.x *= zoom;
        frame->origin.y *= zoom;
        frame->size.width *= zoom;
        frame->size.height *= zoom;        
    }
}

-(long) set_video_subtitle_attribute:(CGRect*)prect fontEffect:(enum FontEffectType)font_effect fontSize:(unsigned long)font_size fontColor:(unsigned long)font_color 
{
	//backup setting
	subt_font_effect = font_effect;
	subt_font_size = font_size;
	subt_font_color = font_color;
    CGPoint center = {0};
    
    //printf("set_video_subtitle_attribute: %d %u %x\n",font_effect,font_size,font_color);
    [self calc_zoom_scale];
    if(subtitle_lable != nil)
    {
        CGFloat size;
        
        //conv frame 
        CGRect frame = (prect) ? (*prect) : subtitle_lable.frame;         
        [self conv_frame_size:&frame];
        center.x = frame.origin.x + (frame.size.width * 0.5);
        center.y = frame.origin.y + (frame.size.height * 0.5);
        subtitle_lable.center = center;
        subtitle_lable.bounds = frame;
        //subtitle_lable.frame = frame;
        
        //conv fontsize        
        size = font_size * zoom;        
        if(font_effect == kDefaultFont)
        {
            subtitle_lable.font = [UIFont systemFontOfSize:(size)];
        }
        else if(font_effect == kBoldFont)
        {
            subtitle_lable.font = [UIFont boldSystemFontOfSize:(size)];
        }
        else //kItalicFont
        {
            subtitle_lable.font = [UIFont italicSystemFontOfSize:(size)];
        }
        
        CGFloat r = ((font_color>>24)&0x00FF) /255.0;
        CGFloat g = ((font_color>>16)&0x00FF) /255.0;
        CGFloat b = ((font_color>> 8)&0x00FF) /255.0;
        CGFloat a = ((font_color    )&0x00FF) /255.0;
        subtitle_lable.textColor = [UIColor colorWithRed:r green:g blue:b alpha:a];
        subtitle_lable.numberOfLines = 10;
        
        //printf("set_video_subtitle_attribute_result: %d %f %f %f %f %f \n",font_effect,size,r,g,b,a);
    }
    if(subtitle_imageview != nil)//conv frame 
    {
        CGRect frame = (prect) ? (*prect) : subtitle_imageview.frame;         
        [self conv_frame_size:&frame];
        center.x = frame.origin.x + (frame.size.width * 0.5);
        center.y = frame.origin.y + (frame.size.height * 0.5);
        subtitle_lable.center = center;
        subtitle_imageview.bounds = frame;
        //subtitle_lable.frame = frame;
    }
    return 0;
    
}

-(long)render_video_subtitle_image:(char *)image_buffer width:(long)image_width height:(long)image_height location:(CGRect*)prect
{
    if(subtitle_lable == nil)
    {
        [self create_video_subtitle:SUBTITLE_TYPE_IMAGE];
    }
    
    if(image_buffer)
    {
        CGDataProviderRef dataPR = CGDataProviderCreateWithData(NULL, image_buffer, image_width*image_height*4, NULL);
        CGColorSpaceRef colorSR = CGColorSpaceCreateDeviceRGB();
        CGImageRef imageR = CGImageCreate(image_width, image_height, 8, 32, image_width*4, colorSR, kCGImageAlphaPremultipliedLast, dataPR, NULL, NO, kCGRenderingIntentDefault);
        subtitle_imageview.image = [UIImage imageWithCGImage:imageR];
        if(dataPR) CGDataProviderRelease( dataPR );
        if(colorSR) CGColorSpaceRelease( colorSR );
    }
    else
    {
        subtitle_imageview.image = nil;     
    }
    
    if(prect)
    {
        CGRect frame = *prect;         
        [self conv_frame_size:&frame];
        subtitle_imageview.frame = frame;
    }
    
    subtitle_imageview.hidden = NO;
    if(subtitle_lable)
    {
        subtitle_lable.hidden = YES;
    }
    return 0;
}

-(long)render_video_subtitle_text:(char *)subtitle location:(CGRect*)prect
{
    if(subtitle_lable == nil)
    {
        [self create_video_subtitle:SUBTITLE_TYPE_TEXT];
    }      
    
    //printf("render_video_subtitle_text: %d %u %x %s\n",subt_font_effect,subt_font_size,subt_font_color,subtitle);
    
    if(subtitle)
    {
        subtitle_lable.text = [NSString stringWithUTF8String:subtitle];     
    }
    else
    {
        subtitle_lable.text = @"";       
    }
    
    if(prect)
    {
        CGRect frame = *prect;      
        [self conv_frame_size:&frame];
        subtitle_lable.bounds = frame;
    }
    
    subtitle_lable.hidden = NO;
    if(subtitle_imageview)
    {
        subtitle_imageview.hidden = YES;
    }
    return 0;
}


- (void)dealloc {
	LOG_FUNC_CALL();
	
		
	NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center removeObserver:self name:UIScreenDidConnectNotification object:nil];
    [center removeObserver:self name:UIScreenDidDisconnectNotification object:nil];
//    [center removeObserver:self name:UIScreenModeDidChangeNotification object:nil];
	
	[self destory_TVout];
	
    [self destory_video_subtitle];
    
	if (render)
	{
		[((ES2Renderer*)render) release];
	}
	if (buffer)
	{
		ekk_free(buffer);
		buffer = NULL;
	}	
	
    [super dealloc];
}

-(long) open_video_subtitle
{
    if(render)
    {
        return [((ES2Renderer*)render) open_video_subtitle];
    }
    return 1;
        
}
-(long) close_video_subtitle
{
    if(render)
    {
        return [((ES2Renderer*)render) close_video_subtitle];
    }
    return 1;
}

-(long)set_video_ps:(long)brightness contrast_name:(long)contrast saturation_name:(long)saturation
{
    if(render)
    {
       // printf("before:brightness=%f,contrast=%f,saturation=%f\n",brightness,contrast,saturation);
        return [((ES2Renderer*)render) set_video_ps:brightness contrast_name:contrast saturation_name:saturation];
    }
    return 1;
}

-(void) pause_video_render
{
    if (!is_render_paused)
    {
        is_render_paused = YES;
        while (is_rendering)
        {
            usleep(1000);
        }
    }
}

-(void) resume_video_render
{
    if (is_render_paused)
    {
        is_render_paused = NO;
    }
}

- (void)setHidden:(BOOL)enabled
{
    if(is_clearing_black)
    {
        black_hidden = enabled;
    }
    else
    {
        super.hidden = enabled;
    }
}

-(void) clear_to_black
{
    //[super setHidden:YES];
    is_clearing_black = YES;
    if (!is_render_paused)
    {
        [self pause_video_render];
        black_hidden = super.hidden;
        super.hidden = YES;
        [self resume_video_render];
    }
    else
    {
        black_hidden = super.hidden;
        super.hidden = YES;
    }
}

-(void) restore_from_black
{
    is_clearing_black = NO;
    if (!is_render_paused)
    {
        [self pause_video_render];
        super.hidden = black_hidden;
        [self resume_video_render];
    }
    else
    {
        super.hidden = black_hidden;
    }
}

@end
